package com.ruoyi.kong.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.kong.bean.NextStepBean;
import com.ruoyi.kong.bean.StepBeanData;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kong.domain.KStep;
import com.ruoyi.kong.service.IKStepService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 命令步骤Controller
 * 
 * @author zeroUp
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/kong/step")
public class KStepController extends BaseController
{
    @Autowired
    private IKStepService kStepService;

    /**
     * 查询命令步骤列表
     */
    @PreAuthorize("@ss.hasPermi('kong:step:list')")
    @GetMapping("/list")
    public TableDataInfo list(KStep kStep)
    {
        startPage();
        kStep.setCreateBy(getUserId().toString());
        List<KStep> list = kStepService.selectKStepList(kStep);
        return getDataTable(list);
    }

    @GetMapping("/getCmdSetGid/{gid}")
    public List<KStep>  getCmdSetGid(@PathVariable("gid") Long gid)
    {
        List<KStep> list = kStepService.selectKStepListOb(gid);
        return list;
    }



    @GetMapping("/getCmdSetGidTest/{gid}")
    public NextStepBean  getCmdSetGidTest(@PathVariable("gid") Long gid)
    {
        NextStepBean nextStepBean = kStepService.selectNextStepBean(gid,null);


        return nextStepBean;
    }


    /**
     * 导出命令步骤列表
     */
    @PreAuthorize("@ss.hasPermi('kong:step:export')")
    @Log(title = "命令步骤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KStep kStep)
    {
        kStep.setCreaterBy(SecurityUtils.getUserId().toString());
        List<KStep> list = kStepService.selectKStepList(kStep);
        ExcelUtil<KStep> util = new ExcelUtil<KStep>(KStep.class);
        util.exportExcel(response, list, "命令步骤数据");
    }

    /**
     * 获取命令步骤详细信息
     */
    @PreAuthorize("@ss.hasPermi('kong:step:query')")
    @GetMapping(value = "/{gid}")
    public AjaxResult getInfo(@PathVariable("gid") Long gid)
    {
        return success(kStepService.selectKStepByGid(gid));
    }

    /**
     * 新增命令步骤
     */
    @PreAuthorize("@ss.hasPermi('kong:step:add')")
    @Log(title = "命令步骤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KStep kStep)
    {
        kStep.setCreaterBy(SecurityUtils.getUserId().toString());
        return toAjax(kStepService.insertKStep(kStep));
    }


    @PostMapping("saveAll")
    public AjaxResult saveAll(@RequestBody List<KStep> kStep)
    {
        return toAjax(kStepService.insertKStepAll(kStep));
    }

    /**
     * 修改命令步骤
     */
    @PreAuthorize("@ss.hasPermi('kong:step:edit')")
    @Log(title = "命令步骤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KStep kStep)
    {
        return toAjax(kStepService.updateKStep(kStep));
    }

    /**
     * 删除命令步骤
     */
    @PreAuthorize("@ss.hasPermi('kong:step:remove')")
    @Log(title = "命令步骤", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gids}")
    public AjaxResult remove(@PathVariable Long[] gids)
    {
        return toAjax(kStepService.deleteKStepByGids(gids));
    }
}
